//
//  LoLVideoCollectionViewCell.m
//  XWZ_News_Work
//
//  Created by penngshi on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LoLVideoCollectionViewCell.h"

@interface LoLVideoCollectionViewCell ()<UICollectionViewDataSource , UICollectionViewDelegate>
@property (nonatomic , strong) UIImageView *titleImageV;
@property (nonatomic , strong) UILabel *titleName;
@property (nonatomic , strong) UICollectionView *collectionV;
@end
@implementation LoLVideoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)layoutSubviews
{

    self.collectionV.frame = CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT);
}

- (void)createSubViews
{
    UICollectionViewFlowLayout *flowL = [[UICollectionViewFlowLayout alloc]init];
    flowL.minimumInteritemSpacing = 5;
    flowL.minimumLineSpacing = 5;
    flowL.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowL.itemSize = CGSizeMake(SCREEN_WIDTH / 2  - 10, SCREEN_WIDTH / 2  - 45);
    self.titleImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    self.titleImageV.backgroundColor = [UIColor colorWithRed:0.98 green:0.9 blue:0.71 alpha:1];
    [self addSubview:self.titleImageV];
    self.titleName = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 40)];
    self.titleName.text = @"斗猫TV";
    self.titleName.textColor = [UIColor grayColor];
    self.titleName.textAlignment = NSTextAlignmentCenter;
    [self.titleImageV addSubview:self.titleName];
    
    self.collectionV = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowL];
    self.collectionV.backgroundColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1];
    self.collectionV.dataSource = self;
    self.collectionV.delegate = self;
    [self.collectionV registerClass:[LoLCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.collectionV.mj_header  = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData)];
    [self.collectionV.mj_header beginRefreshing ];
    
    self.collectionV.mj_footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestData)];
    [self.collectionV.mj_footer beginRefreshing ];
    [self addSubview:self.collectionV];
}

- (void)requestData
{
    [self.delegate refachData];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    LolViewController *lolVC = [[LolViewController alloc]init];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"stopFM" object:nil];
    [self.delegate LolVideoVCDelegate:indexPath.row];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.lolArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LoLCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.lolArr = self.lolArr;
    LolModel *lol = [self.lolArr objectAtIndex:indexPath.row];
    [cell.cententImageV sd_setImageWithURLStr:lol.thumb placeholderImage:[UIImage imageNamed:@"lol-tupian"]];
    cell.superNewTimeLabel.text = lol.nick;
    if (lol.online > 10000) {
        NSString *str = [NSString stringWithFormat:@"%ld",lol.online];
        NSString *str1 = [str substringToIndex:2];
       
        cell.timeLabel.text = [NSString stringWithFormat:@"%@万",str1];
    }
    cell.cententLabel.text = lol.title;

    return cell;
}
- (void)setLolArr:(NSMutableArray *)lolArr
{
    _lolArr = lolArr;
     [self.collectionV.mj_header endRefreshing ];
    [self.collectionV.mj_footer endRefreshing];
}
@end

